<?php
//
// Page Class
// The SDMworld! Network
//

class clsPage extends cDycmsObject
{
	protected $mClsId = 'Page';
	
	private $mTitle;
	private $mHtmlBody;
	private $mHtmlHead;
	private $mParent;
	
	function Render(IDycmsClient &$r_client)
	{
		global $gViewerUrl;
		
		$buf = "<div class=\"page-header\"><a name='page-top'></a> / ";
		$parent = $this->mParent;
		
		$hier = array();
		do
		{
			$obj = dyLoadObject($this->mClsId, $parent);
			if($obj instanceof cDycmsObject)
			{
				$parent = $obj->Get('obj-parent');
				array_push($hier, $obj);
			};
		}while($obj instanceof cDycmsObject);
		
		while($obj = array_pop($hier))
		{
			$buf .= "<a href=\"".dyViewerUrl('Page',
				$obj->GetId()) . "\">".$obj->GetSummary() . "</a> / ";
		};
		
		try
		{
			$q = new cDycmsQuery("obj-parent:".$this->mId);
			$q->SetClass('Page');
			$n = $q->Execute();
		}
		catch(Exception $e) 
		{
			dyLog($e->getMessage());
			$n = 0;
		};
		
		$buf .= $this->mTitle;
		
		for($c=0; $c<$n; $c++)
		{
			
		};
		
		
		$buf .= "</div><div class='page-body'>" . $this->mHtmlBody . 
			"</div><div class=\"page-footer\"><a href=\"#page-top\">".
			uiString("page-top",true) . '</a>';
		
		if($this->CheckPriv(S_MODIFY))
		{
			$buf .= ' - <a href="'.dyEditorUrl($this->mClsId, $this->mId).'"><span class="icon-edit">Edit this page</span></a>';
		};
		
		$buf .= '</div>';
		
		//
		// Render data to client
		//
		
		$r_client->ContentNode()->AddChild(new cHtmlCode($buf));
	}
	
	function DrawEditor(cUiEditor &$editor)
	{
		//
		// Draw the editor form
		//
		
		$editor->AddChild(new cUiEditorTextBox('title', 
			$this->mTitle, "<h3>Page Title</h3>"));
		$editor->AddChild(new cUiEditorTextArea('htmlbody', 
			$this->mHtmlBody, null, true));
	}
	
	function GetSummary()
	{
		return $this->mTitle;
	}
	
	function LoadObject()
	{
		$this->mSummaryValue['title'] = true;
		$this->mSummaryValue['obj-parent'] = true;
		
		$this->mTitle = &$this->mAttributes['title'];
		$this->mHtmlBody = &$this->mAttributes['htmlbody'];
		$this->mHtmlHead = &$this->mAttributes['htmlhead'];
		$this->mParent = &$this->mAttributes['obj-parent'];
	}
	
	function GetAttributes($bVals)
	{
		if($bVals)
		{
			
		}
		else
		{
			return array('title', 'htmlbody', 'htmlhead');
		};
	}

}

?>